<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />	<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>			<!-- jquery 函式庫 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>	<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js" type="text/javascript"></script>				<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script> 					<!-- 本專案自行定義 JS -->


<style type="text/css">

thead th {
	background: #79B7E7;
	color: white;
	vertical-align: middle;
}
thead th.hidden {
	background: white;
}

tbody td.odd {
	background: white;
}
tbody td.even {
	background: #CCCCCC;
}

.dis {
	color: #2E6E9E;
	background: #EAF4FD;
}

</style>

<script type="text/javascript">

function editSubsys(obj) {
	/*初始化****/
	$("#btnDelSubsys").show();
	var subsysId = $(obj).parent("td").next().next().html();	//子系統ID
	var apmrURL = $("#"+subsysId+"APMRsvnUrl").html();			//SVN AP MR 的連線位址	
	var apolURL = $("#"+subsysId+"APOLsvnUrl").html();			//SVN AP OL 的連線位址	
	var cmmrURL = $("#"+subsysId+"CMMRsvnUrl").html();			//SVN CM MR 的連線位址	
	var cmolURL = $("#"+subsysId+"CMOLsvnUrl").html();			//SVN CM OL 的連線位址

	var apmrUSR = $("#"+subsysId+"APMRsvnUsr").html();			//SVN AP MR 的帳號
	var apolUSR = $("#"+subsysId+"APOLsvnUsr").html();			//SVN AP OL 的帳號
	var cmmrUSR = $("#"+subsysId+"CMMRsvnUsr").html();			//SVN CM MR 的帳號
	var cmolUSR = $("#"+subsysId+"CMOLsvnUsr").html();			//SVN CM OL 的帳號
	
	var apmrPWD = $("#"+subsysId+"APMRsvnPwd").val();			//SVN AP MR 的密碼
	var apolPWD = $("#"+subsysId+"APOLsvnPwd").val();			//SVN AP OL 的密碼
	var cmmrPWD = $("#"+subsysId+"CMMRsvnPwd").val();			//SVN CM MR 的密碼
	var cmolPWD = $("#"+subsysId+"CMOLsvnPwd").val();			//SVN CM OL 的密碼
	
	$("#tableEditSubsys input[type='text']:first").val( subsysId ).prop("size",subsysId.length*0.8);
	$("#tableEditSubsys input[type='text']:eq(1)").val( $(obj).parent("td").next().next().next().html() );
	$("#tableEditSubsys input[type='text']:eq(2)").val( cmmrURL ).prop("size",cmmrURL.length*0.9);
	$("#tableEditSubsys input[type='text']:eq(3)").val( cmmrUSR ).prop("size",cmmrUSR.length*0.8);
	$("#tableEditSubsys input[type='password']:first").val( cmmrPWD ).prop("size",cmmrPWD.length*0.8);
	$("#tableEditSubsys input[type='text']:eq(4)").val( cmolURL ).prop("size",cmolURL.length*0.9);
	$("#tableEditSubsys input[type='text']:eq(5)").val( cmolUSR ).prop("size",cmolUSR.length*0.8);
	$("#tableEditSubsys input[type='password']:eq(1)").val( cmolPWD ).prop("size",cmolPWD.length*0.8);
	$("#tableEditSubsys input[type='text']:eq(6)").val( apmrURL ).prop("size",apmrURL.length*0.9);
	$("#tableEditSubsys input[type='text']:eq(7)").val( apmrUSR ).prop("size",apmrUSR.length*0.8);
	$("#tableEditSubsys input[type='password']:eq(2)").val( apmrPWD ).prop("size",apmrPWD.length*0.8);
	$("#tableEditSubsys input[type='text']:eq(8)").val( apolURL ).prop("size",apolURL.length*0.9);
	$("#tableEditSubsys input[type='text']:eq(9)").val( apolUSR ).prop("size",apolUSR.length*0.8);
	$("#tableEditSubsys input[type='password']:eq(3)").val( apolPWD ).prop("size",apolPWD.length*0.8); 
	
	/****初始化*/
	
	$("#divEditSubsys").prop("title","編輯子系統").css("visibility", "visible").dialog({
		resizable:true,width:666,modal:true,show:"fold",hide:"fold",
		buttons : {
			"確定" : function() {
				$(this).dialog("close");
			},"關閉" :function() {
				$(this).dialog("close");
			}
		}
	});
}


$(document).ready(function() {
	init("subsyses.html");
	
	$.ajax({type:"post",url:"QuerySubsys4Maintain",dataType: "json",
		success : function(reses) {
			$.each(reses, function(i,res) {
				var subsysId= res.subsysId;
				var bgColor = ((i+1)%2==1)?"white":"#EAF4FD";
				var color = ((i+1)%2==1)?"black":"#2E6E9E";
				var tmp="<tr><td class='center' rowspan='4'><button type='button' onclick='editSubsys(this);' class='editSubsys'>編輯</button></td><td style='color: "+color+";' bgcolor='"+bgColor+"' rowspan='4'>"+(i+1)+
				"</td><td style='color: "+color+";' bgcolor='"+bgColor+"' rowspan='4'>"+subsysId+
				"</td><td style='color: "+color+";' bgcolor='"+bgColor+"' rowspan='4'>"+res.subsysName+
				"</td><td class='dis' rowspan='2'>CM</td><td>MR</td><td id='"+subsysId+"CMMRsvnUrl'>"+
				((res.isCMMRok)?res['cm']['s4MR'].s2:"")+"</td><td id='"+subsysId+"CMMRsvnUsr'>"+
				((res.isCMMRok)?res['cm']['s4MR'].s3:"")+"</td><td><input id='"+subsysId+"CMMRsvnPwd' type='hidden' value='"+
				((res.isCMMRok)?res['cm']['s4MR'].s4:"")+"'></td></tr><tr><td class='dis'>OL</td><td class='dis' id='"+subsysId+"CMOLsvnUrl'>"+
				((res.isCMOLok)?res['cm']['s4OL'].s2:"")+"</td><td class='dis' id='"+subsysId+"CMOLsvnUsr'>"+
				((res.isCMOLok)?res['cm']['s4OL'].s3:"")+"</td><td><input id='"+subsysId+"CMOLsvnPwd' type='hidden' value='"+
				((res.isCMOLok)?res['cm']['s4OL'].s4:"")+"'></td></tr><tr><td class='dis' rowspan='2'>AP</td><td>MR</td><td id='"+subsysId+"APMRsvnUrl'>"+
				((res.isAPMRok)?res['ap']['s4MR'].s2:"")+"</td><td id='"+subsysId+"APMRsvnUsr'>"+
				((res.isAPMRok)?res['ap']['s4MR'].s3:"")+"</td><td><input id='"+subsysId+"APMRsvnPwd' type='hidden' value='"+
				((res.isAPMRok)?res['ap']['s4MR'].s4:"")+"'></td></tr><tr><td class='dis'>OL</td><td class='dis' id='"+subsysId+"APOLsvnUrl'>"+
				((res.isAPOLok)?res['ap']['s4OL'].s2:"")+"</td><td class='dis' id='"+subsysId+"APOLsvnUsr'>"+
				((res.isAPOLok)?res['ap']['s4OL'].s3:"")+"</td><td><input id='"+subsysId+"APOLsvnPwd' type='hidden' value='"+
				((res.isAPOLok)?res['ap']['s4OL'].s4:"")+"'></td></tr>";
				
				$("#tbodySubsys").append(tmp);
			});
			
			$("#tbodySubsys button").button();
		
		},error : function(xhr, ajaxOptions, thrownError) { errorAjx(xhr); }
	});
	
	
	$("#tbodyEditSubsys tr:even").attr("bgcolor","white");
	$("#tbodyEditSubsys tr:odd").attr("bgcolor","#EAF4FD");
	
	
	
	$(".testSVN").bind("click", function(){
		$("#msgINdialog").html("");
		var url = $(this).parent("td").prev().prev().prev().children("input").val();
		var usr = $(this).parent("td").prev().prev().children("input").val();
		var pwd = $(this).parent("td").prev().children("input").val();
	
		var res = chkSVNconnection(url,usr,pwd);
		$("#msgINdialog").html(transSVNconnCode(res)+",  "+currentDateTime() );
	});
	
	$("#btnAddSubsys").bind("click", function(){
		/*初始化****/
		$("#btnDelSubsys").hide();
		$("#tableEditSubsys input[type='text']").val("");
		/****初始化*/
		
		$("#divEditSubsys").prop("title","新增子系統").css("visibility", "visible").dialog({
			resizable:true,width:635,modal:true,show:"fold",hide:"fold",
			buttons : {
				"確定" : function() {
					$(this).dialog("close");
				},"關閉" :function() {
					$(this).dialog("close");
				}
			}
		});
	
	});
	
	$("button").button();
});
</script>

</head>
<body>
	<div id="header"></div>
	
	<table id="tableSubsys">
		<thead class="tableFirst">
		<tr>
			<th><button id="btnAddSubsys" type="button">新增</button></th>
			<th>#</th>
			<th>子系統ID</th>
			<th>子系統名稱</th>
			<th>所屬</th>
			<th>MorO</th>
			<th>SVN URL</th>
			<th>SVN登入帳號</th>
			<th class="hidden"></th>
		</tr>
		</thead>
		
		<tbody id="tbodySubsys"></tbody>
	</table>

<!-- 選取需求的對話窗 -->
<div class="dialog" id="divEditSubsys">
	<div id="msgINdialog">&nbsp;</div>
	<br/>
	
	<table id="tableEditSubsys">
		<thead>
			<tr>
				<th class="right" colspan="2">ID：</th>
				<td class="left" colspan="4"><input type="text" size="8" maxlength="10" /></td>
			</tr>
			<tr>
				<th class="right" colspan="2">名稱：</th>
				<td class="left" colspan="3"><input type="text" size="10" maxlength="40" /></td>
				<td><button type="button" id="btnDelSubsys">刪除</button></td>
			</tr>
			<tr><td colspan="6">&nbsp;</td></tr>
			<tr><td colspan="6">&nbsp;</td></tr>
			
			<tr>
				<th>所屬</th>
				<th>MorO</th>
				<th>SVN URL</th>
				<th>SVN 登入帳號</th>
				<th>SVN 登入密碼</th>
				<td>&nbsp;</td>
			</tr>
		</thead>
		<tbody id="tbodyEditSubsys">
			<tr class="odd">
				<td rowspan="2">CM</td>
				<td>MR</td>
				<td><input type="text" size="14" maxlength="100"> </td>
				<td><input type="text" size="10" maxlength="14"> </td>
				<td><input type="password" size="10" maxlength="20"> </td>
				<td><button type="button" class="testSVN">test</button></td>
			</tr>
			<tr class="even">
				<td>OL</td>
				<td><input type="text" size="14" maxlength="100"> </td>
				<td><input type="text" size="10" maxlength="14"> </td>
				<td><input type="password" size="10" maxlength="20"> </td>
				<td><button type="button" class="testSVN">test</button></td>
			</tr>
			<tr class="odd">
				<td rowspan="2">AP</td>
				<td>MR</td>
				<td><input type="text" size="14" maxlength="100"> </td>
				<td><input type="text" size="10" maxlength="14"> </td>
				<td><input type="password" size="10" maxlength="20"> </td>
				<td><button type="button" class="testSVN">test</button></td>
			</tr>
			<tr class="even">
				<td>OL</td>
				<td><input type="text" size="14" maxlength="100"> </td>
				<td><input type="text" size="10" maxlength="14"> </td>
				<td><input type="password" size="10" maxlength="20"> </td>
				<td><button type="button" class="testSVN">test</button></td>
			</tr>
		</tbody>
	</table>
</div>
</body>
</html>